﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Diagnostics;
using OpenLS.Spreadsheet.Formats;

namespace OpenLS.Spreadsheet
{
    class FormatManager
    {
        private static FormatManager _instance;

        private FormatManager()
        {
            Formats = new List<SpreadsheetFormat>();
            try
            {
                var directoryCatalog = new DirectoryCatalog(".");
                var container = new CompositionContainer(directoryCatalog);
                container.ComposeParts(this);
            }
            catch(Exception exp)
            {
                Debug.WriteLine(exp);
            }
        }
        public static IEnumerable<SpreadsheetFormat> DataFormats
        {
            get
            {
                if (_instance == null)
                    _instance = new FormatManager();
                return _instance.Formats;
            }
        }

        [ImportMany]
        public List<SpreadsheetFormat> Formats { get; set; }
        
    }
}